local timer = require("timer")

local M = {}
M.new = function (ctx, initParam)
    local handler = function (req, resp)
        local thread = coroutine.running()
        local finish = function ()
            coroutine.resume(thread)
        end
        timer.setTimeout(2000, function ()
            local body = "async response"
            resp.statusCode = 200
            resp:setHeader("Content-Type", "text/html")
            resp:setHeader("Content-Length", string.len(body))
            resp:write(body)
            finish()
        end)
        coroutine.yield()
    end
    return handler
end

local moduleName = ...
_G[moduleName] = M
complex = M
return complex